import requests
import os
import json

Gitee_AI_API_KEY = os.environ.get(
    "Gitee_AI_API_KEY", "")


API_URL = "https://ai.gitee.com/api/inference/serverless/KGHCVOPBV7GY/chat/completions"
headers = {
    "Authorization": f"Bearer {Gitee_AI_API_KEY}",
    "Content-Type": "application/json"
}


def query(payload):
    response = requests.post(API_URL, headers=headers,
                             json=payload, stream=False)
    return response.json()


# try:
#     res = query(
#         {
#             "messages": [
#                 {
#                     "role": "system",
#                     "content": "你是一个文生图 Prompt 翻译器，将中文翻译为英文，直接输出你答案"
#                 },
#                 {
#                     "role": "user",
#                     "content": "美丽的白色樱花盛开，在晴朗的天空背景下，树枝上精致而新鲜的花朵，柔和对焦的摄影，采用日式风格，搭配微距镜头，利用自然光，捕捉春天的气息，色调清新。--ar 128:85 --v 6.0 --style raw"
#                 }
#             ],
#             "stream": False

#         })

#     print(json.dumps(res, indent=2, ensure_ascii=False))

#     print(res["choices"][0]["message"]["content"])

# except Exception as e:
#     print("请求失败")
#     print(f"Error: {e}")
